package Listeners;

import Helpers.ContextHelper;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;


public class CustomLocationListener implements LocationListener
{
	private static Location lastKnownLocation;
	
	public CustomLocationListener(){ 
		
	}
	
	public static void startListening(){
		LocationManager lm = (LocationManager)ContextHelper.getContextInstance().getSystemService(Context.LOCATION_SERVICE);    	
    	LocationListener listener = new CustomLocationListener();
    	lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);
	}
	
	public static Location getCurrentLocation(){
		return lastKnownLocation;		
	}

	@Override
	public void onLocationChanged(Location loc)	{			
		if(loc!=null){
			lastKnownLocation = loc;
		}
	}

	@Override
	public void onProviderDisabled(String provider){

		
	}

	@Override
	public void onProviderEnabled(String provider){
		

	}
	
	@Override
	public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
		
	}

}